<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>props</title>
  </head>
  <div id="app"></div>

  <body>
    <script src="../../public/js/react.development.js"></script>
    <script src="../../public/js/react-dom.development.js"></script>
    <script src="../../public/js/babel.min.js"></script>
    <script src="../../public/js/prop-types.js"></script>
    <script type="text/babel">
      function Person() {
        //对prop进行限制，使用static把规则加到class上，不加class属性会加到实例上
        const { name, age, speak, address } = this.props;
        return (
          <ul onClick={speak}>
            <li>名字:{name}</li>
            <li>年龄:{age}</li>
            <li>地址:{address}</li>
          </ul>
        );
      }
      Person.propTypes = {
        name: PropTypes.string.isRequired,
        age: PropTypes.number,
        speak: PropTypes.func,
      };
      Person.defaultProps = {
        address: "新乡",
      };

      ReactDOM.render(
        <Person {...p} speak={speak} />,
        document.getElementById("app")
      );
    </script>
  </body>
</html>
